<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="日期区间">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-top"
          size="mini"
          :disabled="single"
          v-hasPermi="['business:integrate:dyvmMessage:export']"
          @click="handleUpdate"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dyvmMessageList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="index" label="序号" width="50"/>
      <el-table-column label="手机号" align="center" prop="phoneNum" width="120" />
      <el-table-column label="告警时间" align="center" prop="time" width="180"/>
      <el-table-column label="设备编码" align="center" prop="code" width="200" />
      <el-table-column label="告警内容" align="center" prop="content" />
      <el-table-column label="语音类型" align="center" prop="msgType" width="80" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.dyvm_templat_type" :value="scope.row.msgType"/>
        </template>
      </el-table-column>
      <el-table-column label="拨打状态" align="center" prop="status" width="80" >
        <template slot-scope="scope">
          <!--状态：0-成功，1-失败-->
          <el-tag type="danger" v-if="scope.row.status=='0'">成功</el-tag>
          <el-tag type="success" v-if="scope.row.status=='1'">失败</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="拨打时间" align="center" prop="sendTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.sendTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
  import { listDyvmMessage} from "@/api/business/integrate/dyvmMessage"
  export default {
    name: "DyvmMessage",
    dicts: ['dyvm_templat_type'],
    data() {
      return {
        // 日期范围
        dateRange: [],
        disabled:false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 语音发送记录数据
        dyvmMessageList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {},
      }
    },
    created() {
      this.getList()
    },
    methods: {
      /** 查询语音发送列表 */
      getList() {
        this.loading = true
        listDyvmMessage(
          this.addDateRange(this.queryParams, this.dateRange)
        ).then(response => {console.log(response)
          this.dyvmMessageList = response.rows
          this.total = response.total
          this.loading = false
        })
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1
        this.getList()
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm")
        this.handleQuery()
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!=1
        this.multiple = !selection.length
      },
    }
  }
</script>
